//
//  WriteTextViewController.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/11/10.
//  Copyright © 2017年 bob. All rights reserved.
//

#import "WriteTextViewController.h"
#import "UITextView+Placeholder.h"
@interface WriteTextViewController ()

@property(nonatomic,strong)UITextView *ContentTextView;

@property(nonatomic,copy)FinshBlock SureBlock;

@property(nonatomic,strong)UIView *bagView;


@end

@implementation WriteTextViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.005 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
 
        [self.ContentTextView becomeFirstResponder];
        
    });

    // Do any additional setup after loading the view.
}





-(instancetype)initWithPloader:(NSString*)ploachStr andTipName:(NSString*)tipName andOrinStr:(NSString*)Orinstr andFinshBlock:(FinshBlock)block
{
    if (self=[super init]) {
        
        
        self.bagView=[[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT-180-200, SCREEN_WIDTH, 180)];
        
        self.bagView.backgroundColor=TBColorTableViewBg;
  
        
        UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, 15, 200, 30)];
        
        titleLabel.textColor=TBColorProvideBtnbg;
        
        titleLabel.textAlignment=NSTextAlignmentLeft;
        
        titleLabel.font=[UIFont systemFontOfSize:18];
        
        titleLabel.text=tipName;
        
        [self.bagView addSubview:titleLabel];
        
        
        UIButton *SureBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        
        SureBtn.frame=CGRectMake(self.bagView.width-75, 15, 60, 30);
        
        [SureBtn setTitle:@"确定" forState:UIControlStateNormal];
        
        [SureBtn setTitleColor:TBColorProvideBtnbg forState:UIControlStateNormal];
        
        SureBtn.layer.cornerRadius=2.0;

        SureBtn.backgroundColor=TBColorProvideBtnbg;
        
        [SureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
 
        [SureBtn addTarget:self action:@selector(SureAction:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.bagView addSubview:SureBtn];
        
        self.ContentTextView=[[UITextView alloc]initWithFrame:CGRectMake(15,55, SCREEN_WIDTH-30, 100)];
        
        self.ContentTextView.placeholder=ploachStr;
        
        self.ContentTextView.text=Orinstr;
        
        self.ContentTextView.font=[UIFont systemFontOfSize:15];
        
        self.ContentTextView.textColor=[UIColor darkGrayColor];
        
        self.ContentTextView.layoutManager.allowsNonContiguousLayout = NO;
  
        self.ContentTextView.layer.borderWidth=1.0;
        
        self.ContentTextView.layer.borderColor=[UIColor groupTableViewBackgroundColor].CGColor;

         self.ContentTextView.inputAccessoryView = [[UIView alloc] init];
        
        [self.bagView addSubview:self.ContentTextView];
   
         [self.view addSubview:self.bagView];
     
        _SureBlock=block;
        
    }
    
    return self;
}



-(void)SureAction:(UIButton*)sender
{
    
    [self.ContentTextView resignFirstResponder];

    [self dismissViewControllerAnimated:YES completion:^{

    }];
    
    _SureBlock(self.ContentTextView.text);
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    
    [self.ContentTextView resignFirstResponder];

    
    [self dismissViewControllerAnimated:YES completion:^{
        
       
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
